package com.woniuxy.kaer.system.controller;


import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.system.annotation.RequirePermission;
import com.woniuxy.kaer.system.annotation.RequireRole;
import com.woniuxy.kaer.system.model.RoleManager;
import com.woniuxy.kaer.system.service.RoleManagerService;
import com.woniuxy.kaer.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sun
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/roleManager")
@Api(tags ="角色账户管理")
public class RoleManagerController {
    @Resource
    private RoleManagerService roleManagerService;
    @Resource
    private JwtUtil jwtUtil;

    //角色分配
    @PostMapping("/addRole")
    @ApiOperation("分配角色")
    @RequireRole("BOSS")
    @RequirePermission("/roleManager/addRole")
    public Result addRole(Integer roleId,@RequestHeader("token") String token) throws Exception{
        Integer managerId = jwtUtil.getManagerId1(token);
        roleManagerService.addRole(roleId, managerId);
        return Result.succeed("添加成功",null);
    }

    //给其他管理员分配角色
    @PostMapping("/addRoleForOther")
    @ApiOperation("给其他管理员分配角色")
    @RequireRole("BOSS")
    @RequirePermission("/roleManager/addRoleForOther分配角色")
    public Result addRoleForOther(Integer roleId,Integer managerId,@RequestHeader("token") String token) throws Exception{
        Integer otherId = jwtUtil.getManagerId1(token);
        roleManagerService.addRoleForOther(roleId, managerId,otherId);
        return Result.succeed("添加成功",null);
    }

    //删除管理员角色
    @PostMapping("/deleteRole")
    @ApiOperation("删除角色")
    @RequirePermission("/roleManager/deleteRole")
    @RequireRole("BOSS")
    public Result deleteRole(Integer roleId,@RequestHeader("token") String token) throws Exception{
        Integer managerId = jwtUtil.getManagerId1(token);
        roleManagerService.deleteRole(roleId, managerId);
        return Result.succeed("删除成功",null);
    }

}

